<template>
  <div class="app-container">
    <el-dialog
      title="选择设备"
      :visible.sync="dialogTableVisible"
      :close-on-click-modal="false"
      :before-close="close"
      width="900px">
    <el-form :model="selectForm" ref="queryForm" :inline="true">
      <el-form-item label="设备编号：">
        <el-input size="small" v-model="selectForm.deviceCode" placeholder="请输入设备编号" clearable/>
      </el-form-item>
      <el-form-item label="设备名称：">
        <el-input size="small" v-model="selectForm.deviceName" placeholder="请输入设备名称" clearable/>
      </el-form-item>
      <el-form-item label="设备状态：">
        <el-select v-model="selectForm.deviceStatus" placeholder="请选择" clearable>
          <el-option
            v-for="item in deviceStatusList"
             :key="item.id" :label="item.statusName" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属部门：">
        <department @addSelectChange="addSelectChange"></department>
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list" border  @selection-change="currentChange">
      <el-table-column type="selection" width="55" />
      <el-table-column type="index" align="center" label="序号" width="55" :index="indexMethod"/>
      <el-table-column align="center" label="设备编号" prop="deviceCode" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="设备名称" prop="deviceName" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="设备品牌" prop="deviceBrandsName" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="规格型号" prop="deviceModel" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="状态" prop="deviceStatus" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{scope.row.deviceStatus|setDeviceStatus(deviceStatusList)}}
        </template>
      </el-table-column>
      <el-table-column align="center" label="所属部门" prop="deptName" :show-overflow-tooltip="true"/>

    </el-table>
    <pagination
      :page-sizes="[5,10,20,50]"
      :page-size="selectForm.pageSize"
      :total="total"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" type="info" @click="$emit('selectChange')">取消</el-button>
        <el-button size="mini" type="primary" @click="submit">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {deviceList,deviceLists} from '@/api/scrap/index'
  import department from "./department";
  import  {deviceStatus} from '@/api/basicInformation/index'
  export default {
    name: "addDialog.vue",
    components:{
      department
    },
    data() {
      return {
        dialogTableVisible:true,
        loading: false,//加载
        selectForm: {
          deviceCode: '',//设备编号
          deviceName: '',//设备名称
          deviceStatus: '',//
          deviceModel: '',//
          departmentId: '',//
          pageNum: 1,
          pageSize: 5,
        },//查询条件
        list: [],//数据
        total: 0,
        selectDate: '',//时间
        deviceStatusList:[],
        selectData:'',
      }
    },
    created() {
      this.init()
    },
    methods: {
      async init(){
        await this.getDeviceStatus()
        await this.getList()
      },
      /** 查询设备状态*/
      async getDeviceStatus() {
        let res = await deviceStatus()
        this.deviceStatusList = res.rows
        console.log(this.deviceStatusList)
      },
      async getList() {
        this.loading = true
        let res = await deviceList(this.selectForm)
        this.list = res.rows
        this.total = res.total
        this.loading = false
      },
      indexMethod(index){
        return this.selectForm.pageSize*(this.selectForm.pageNum-1)+(index+1)
      },
      close(){
        this.$emit('selectChange')
      },
     currentChange(val){
        this.selectData=val
      },
      submit(){
        if(this.selectData){
          this.$emit('selectChange',this.selectData)
        }
      },
      addSelectChange(address){
        this.selectForm.departmentId=address
      },

    },
    filters:{
      setDeviceStatus(sta,deviceStatusList){
        let a
        deviceStatusList.forEach((i)=>{
          if(i.id==sta){
             a =i.statusName
          }
        })
        return a
      }
    }
  }
</script>

<style scoped>
  .bule {
    color: #2196F3;
    cursor: pointer
  }
</style>
